package com.ze.commontool;

import java.io.IOException;
import android.media.MediaPlayer;

public class SoundPlayComment {

	
	private static SoundPlayComment instance;
	public static MediaPlayer mediaPlayer = null;
	
	private SoundPlayComment() {
		
	}
	
	public static SoundPlayComment getInstance() {
		if (instance == null) {
			instance = new SoundPlayComment();
		}
		
		return instance;
	}
	
	
	public void start(String string) {
		//mediaPlayer.reset();
		mediaPlayer = new MediaPlayer();
		try {
			mediaPlayer.setDataSource(string);
			mediaPlayer.prepare();
			mediaPlayer.start();
			mediaPlayer.setLooping(false);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void pause() {
		if (mediaPlayer.isPlaying()) {// 正在播放
			mediaPlayer.pause();// 暂停
		} else {// 没有播放
			mediaPlayer.start();
		}
	}
	
	public void stop() {
		if (mediaPlayer != null && mediaPlayer.isPlaying()) {
			mediaPlayer.stop();
			mediaPlayer.release();
			mediaPlayer = null;
		}
	}
	
	public void deStroySound() {
		if (mediaPlayer != null) {
			if (mediaPlayer.isPlaying()) {
				mediaPlayer.stop();
			}
			mediaPlayer.release();
			mediaPlayer = null;
		}
	}
	
}
